<?php  session_start();  ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <?php 
        //Delete Task//////////Done
        $i;
       $Exp_id= $_SESSION['id_Exp'];
        for ($i=1;$i<=5;$i++)
        {
        if ($_POST['t'.$i] != null){$task_id =$_POST['t'.$i];break;}
        }
        
                $con= mysql_connect("localhost","root","");
        if(!$con){
die('Connection Error!:' . mysql_error());
}
mysql_select_db ("usabilityevaluation",$con);
        $query1= "DELETE  FROM task WHERE id_task='$i' and id_experiment=$Exp_id"; 
        $query2="Select count(id_task) FROM task WHERE id_experiment=$Exp_id";
         $result=mysql_query($query2) or die('Error, deletee query failed task');
      @mysql_query($query1) or die('Error, deletee query failed task');
      //retrieve count of question to delete
         $query3="Select count(id_question),id_question FROM question WHERE id_exp=$Exp_id";
         $result3=mysql_query($query3) or die('Error, deletee query failed task');
         
      while($row2 = mysql_fetch_array($result)){$count=$row2[0];}
    //    for ($y=1;$y<=$count;$y++){    }
$query2= "DELETE FROM question WHERE id_task='$i' and id_exp=$Exp_id";
//retrieve question ID
  while($row3= mysql_fetch_array($result3)){
  $query3= "DELETE FROM answers WHERE id_question=$row3[1]";
  @mysql_query($query3) or die('Error, deletee query failed asnwers');
    }
        echo "DELETE DONE";
 header("Location: {$_SERVER['HTTP_REFERER']}"); 
mysql_close($con);
        
        ?>
    </body>
</html>
